<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    /**
     * @param {number[]} numbers
     * @param {number} target
     * @return {number[]}
     */
    var twoSum = function(numbers, target) {
      let i = 0,
        j = numbers.length - 1,
        arr = [];
      while (i < j) {
        let sum = numbers[i] + numbers[j];
        if (sum < target) {
          i++;
        } else if (sum > target) {
          j--;
        } else {
          arr[0] = i + 1;
          arr[1] = j + 1;
          return arr;
        }
      }
      return arr;
    };
    console.log(twoSum([2, 7, 11, 15], 9));
  </script>
</html>
